<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.7
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############





if(Antz_IntelliForm::submitted('new-connection')){
    $name = post('name');
    $url = post('url');
    $username = post('username');
    $password = post('password');
    $salt = post('cryptSalt');

    $error = false;

    if(trim($name)==''){
        $error = true;
        JFX::addError('Title cannot be blank');
    }

    if(trim($username)==''){
        $error = true;
        JFX::addError('Username cannot be blank');
    }

    if(trim($password)==''){
        $error = true;
        JFX::addError('Password cannot be blank');
    }

    if(trim($url)==''){
        $error = true;
        JFX::addError('URL cannot be blank');
    }

    if(substr($url, 0, 7)!=='http://' && substr($url, 0, 8)!=='https://'){
        $error = true;
        JFX::addError('URL must begin with http:// or https://');
    }

    if(!$error){
        $dbParams = array(
            'url' => $url,
            'username' => $username,
            'pass' => $CRYPT->crypt($password),
            'crypt_salt' => $CRYPT->crypt($salt)
        );
        $id = $DB->insert($CONFIG->dbprefix.'vms_servers', $dbParams);
        $this->updateContentLang('conn_title', $id, $name, '*', '*');
        JFX::addSuccess('Update success!');
        JFX::redirect(THIS_PAGE_URL);
    }
}

























$formFields = array(
    array(
        'type' => 'text',
        'name' => 'name',
        'value' => post('name', $this->getContentLang('conn_title', $connid)),
        'label' => 'Connection Name'
    ),
    array(
        'type' => 'text',
        'name' => 'url',
        'value' => post('url', $cData['url']),
        'label' => 'URL'
    ),
    array(
        'type' => 'text',
        'name' => 'username',
        'value' => post('username', $cData['username']),
        'label' => 'Username'
    ),
    array(
        'type' => 'password',
        'name' => 'password',
        'value' => post('password', $CRYPT->decrypt($cData['password'])),
        'label' => 'Password'
    ),
    array(
        'type' => 'text',
        'name' => 'cryptSalt',
        'value' => post('cryptSalt'),
        'label' => 'Crypt Salt'
    ),
    array(
        'type' => 'submit',
        'name' => 'submitBtn',
        'value' => 'Save',
        'label' => '&nbsp;'
    )
);

echo JFX::makeRapidForm($formFields, 'New connection details', 'new-connection');

